#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
string s[20];
int n,m;
int a[N],c[N];
int x[4];
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin >> n >> m;
    for(int i = 1;i <= n;i++) cin >> a[i];
    for(int i = 1;i <= m;i++) cin >> c[i];
    for(int i = 1;i <= floor(log2(n)+1);i++) cin >> s[i];
    int T;cin >> T;
    while(T--){
        for(int i = 0;i <= 3;i++) cin >> x[i];
        for(int i = 1;i <= n;i++){
            for(int j = 0;j < 4;j++) a[i] ^= x[j];
        }
        int ans = 0;
        for(int i = 1;i <= n;i++) ans ^= a[i];
        cout << T << "\n";
    }
    return 0;
}
